home *** CD-ROM | disk | FTP | other *** search
- Path: freenet.vancouver.bc.ca!zipz
- From: zipz@opus.freenet.vancouver.bc.ca (Patrick Wong)
- Newsgroups: comp.lang.c
- Subject: fclose() and remove() within a funct'n
- Date: 12 Feb 1996 20:43:40 GMT
- Organization: Vancouver Regional FreeNet
- Message-ID: <4fo8ps$3v6@milo.freenet.vancouver.bc.ca>
- NNTP-Posting-Host: opus.freenet.vancouver.bc.ca
- Summary: How does one use the atexit() function to close and remove a file?
- X-Newsreader: TIN [version 1.2 PL2]
-
- I'm writing a function that is supposed to close and remove temporary files
- on a DOS machine. I'm posting this in c.l.c because it's a C question as
- well as a DOS question.
- I am using the atexit() function to close the temporary file before
- exiting the function. Yet the atexit() function will not allow me to
- pass a pointer to the file that I want to close (and delete). The
- function MUST be responsible for closing and deleting all temporary files
- it creates upon PROGRAM termination (hence the atexit() function).
-
- Here is the function:
-
- FILE *tempname(char *filename, char *mode)
- {
- FILE *fptemp;
- char *ptemp;
- const char fnlen = 13;
-
- if ((ptemp = (char *)malloc(fnlen * sizeof(char))) == NULL)
- return NULL;
- ptemp = (filename == NULL) ? tmpnam(NULL) : tmpnam(filename);
- return (((fptemp = fopen(filename, mode)) == NULL) ? NULL : fptemp);
- }
- /* so how do I add the functionality descrbed above? */
- /* I believe tmpnam() if a non-ansi function ... is it? */
-
-
- --
-
- /* Name : Patrick Wong : "Jean Cretien, thank you for */
- /* E-mail : zipz@freenet.vancouver.bc.ca : saving our country; thank us */
- /* Occupation : Student/Programmer : for saving your Job!" */
- /* School : BCIT - Computer Systems : -- an intelligent citizen */
-